//
//  AppDelegate.m
//  RoadLine
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 RedFireNoodles. All rights reserved.
//

#import "AppDelegate.h"
#import "HomeViewController.h"
#import "DestinationViewController.h"
#import "Constants.h"
#import "ProductViewController.h"
#import "MineViewController.h"

// 分享
#import <ShareSDK/ShareSDK.h>
#import "WXApi.h"
#import "WeiboApi.h"
#import "WeiboSDK.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    // 主页推荐
    HomeViewController *homeVC = [[HomeViewController alloc] init];
    UINavigationController *homeNavVC = [[UINavigationController alloc] initWithRootViewController:homeVC];
    homeNavVC.navigationBar.barTintColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:1];
    homeNavVC.navigationBar.translucent = NO;
    homeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:kRecommendName image:[UIImage imageNamed:kRecommendImageName] tag:1000];
    
    // 目的地
    DestinationViewController *destVC = [[DestinationViewController alloc] init];
    UINavigationController *destNavVC = [[UINavigationController alloc] initWithRootViewController:destVC];
    destNavVC.navigationBar.barTintColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:1];
    destNavVC.navigationBar.translucent = NO;
    destVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:kDestinationName image:[UIImage imageNamed:kDestinationImageName] tag:1001];
    
    // 特价
    ProductViewController *prodVC = [[ProductViewController alloc] init];
    UINavigationController *prodNavVC = [[UINavigationController alloc] initWithRootViewController:prodVC];
    prodNavVC.navigationBar.barTintColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:1];
    prodNavVC.navigationBar.translucent = NO;
    prodVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"特价" image:[UIImage imageNamed:@"iconfont-tejia.png"] tag:1002];
    
    // 我的
    MineViewController *mineVC = [[MineViewController alloc] init];
    UINavigationController *mineNavVC = [[UINavigationController alloc] initWithRootViewController:mineVC];
    mineNavVC.navigationBar.barTintColor = [UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:1];
    mineNavVC.navigationBar.translucent = NO;
    
    mineVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"iconfont-self"] tag:1003];
    

    // 下方TabBar
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.viewControllers = [NSArray arrayWithObjects:homeNavVC, destNavVC, prodNavVC, mineNavVC, nil];
    tabBar.tabBar.translucent = NO;
    
   

    // 设置整个tabbar颜色(两种方法:)
    tabBar.tabBar.barTintColor = [UIColor whiteColor];
    //    [[UITabBar appearance]setBarTintColor:[UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:1]];
    
    // 设置选中bar的颜色
    [[UITabBar appearance]setTintColor:[UIColor colorWithRed:246/255.0 green:85/255.0 blue:91/255.0 alpha:1]];
    
    // 设置选中图标时显示的图片:
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selectImage.png"]];
    
    // 设置tabbar背景图片方法:
    // UIImage* tabBarBackground = [UIImage imageNamed:@"iconfont-xuanzhong.png.png"];
    // [[UITabBar appearance] setBackgroundImage:tabBarBackground];
    
    self.window.rootViewController = tabBar;
    
    [homeNavVC release];
    [homeVC release];
    [destNavVC release];
    [destVC release];
    [_window release];
    
    
    // 为开机动画开辟一个多线程 防止播放动画延迟的时候占用主程序
    [self performSelectorInBackground:@selector(bootAnimate) withObject:nil];
    
    // 分享
    [ShareSDK registerApp:@"71a2f6720bbf"];
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                             redirectUri:@"http://www.sharesdk.cn"];
    //当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
    [ShareSDK  connectSinaWeiboWithAppKey:@"568898243"
                                appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                              redirectUri:@"http://www.sharesdk.cn"
                              weiboSDKCls:[WeiboSDK class]];
    
    //添加腾讯微博应用 注册网址 http://dev.t.qq.com
    [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
                                  appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
                                redirectUri:@"http://www.sharesdk.cn"
                                   wbApiCls:[WeiboApi class]];
//    //添加微信应用 注册网址 http://open.weixin.qq.com
//    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
//                           wechatCls:[WXApi class]];
//    //微信登陆的时候需要初始化
//    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
//                           appSecret:@"64020361b8ec4c99936c0e3999a9f249"
//                           wechatCls:[WXApi class]];
    
    
    return YES;
}

// 实现开机动画的方法
- (void)bootAnimate
{
    // 建立画布并开辟空间
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    imageView.image = [UIImage imageNamed:@"BOOT750x1334"];
    [self.window addSubview:imageView];
    
    // 设置初始透明度:
    imageView.alpha = 1;
    // 使用系统方法
    [UIView animateWithDuration:2.0f delay:1.0f options:UIViewAnimationOptionCurveLinear animations:^{
        // 设置渐变的透明度
        imageView.alpha = 0.99;
    } completion:^(BOOL finished) {
        [NSThread sleepForTimeInterval:0.3f];
        [imageView removeFromSuperview];

    }];
}





- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
